const fs = require('fs');
const execa = require('execa');

const pkgs = fs.readdirSync('packages').filter(p => {
  // statSync() 方法返回文件信息状态 isDirectory()如果是文件目录则返回true
  return fs.statSync(`packages/${p}`).isDirectory();
});
const runParallel = (targets, buildFn) => {
  const res = [];
  for (const target of targets) {
    res.push(buildFn(target));
  }
  return Promise.all(res);
};

const build = async pkg => {
  await execa('rollup', ['-c', '--environment', `TARGET:${pkg}`], { stdio: 'inherit' });
};

runParallel(pkgs, build);
